import json
from pyecharts.charts import Map
from pyecharts.options import *
f=open("D:\\疫情.txt","r",encoding="UTF-8")
data=f.read()
f.close()
#将字符串json转换为python字典
data_dict=json.loads(data)
province_data_list=data_dict["areaTree"][0]["children"]
data_list=[]#绘图数据所需列表
for province_data in province_data_list:
    province_name=province_data["name"]+"省"#省份名称
    province_confirm=province_data["total"]["confirm"]#确证人数
    data_list.append((province_name,province_confirm))
print(data_list)
map=Map()
map.add("个省份确诊人数",data_list,"china")
map.set_global_opts(
    title_opts=TitleOpts(title="全国疫情地图"),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min":1,"max":99,"lable":"1-99人","color":"CCFFFF"},
            {"min":100,"max":999,"lable":"1-99人","color":"#30f415"},
            {"min":1000,"max":4999,"lable":"1-99人","color":"#f4dc15"},
            {"min":5000,"max":9999,"lable":"1-99人","color":"#6696f4"},
            {"min":10000,"max":99999,"lable":"1-99人","color":"#f466e6"},
            {"min":100000,"lable":"1-99人","color":"#f46866"}
        ]
    )
)
map.render("全国疫情.html")